package com.itboye.mengwu.data.presenter;

import java.util.List;
import java.util.Observer;

import android.util.Log;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.object.BasePresenter;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.app.ui.main.MainPresenter;
import com.itboye.mengwu.data.interfaces.IShopCar;
import com.itboye.mengwu.data.model.GoodsDetailBean;
import com.itboye.mengwu.data.model.ShopCarBean;
import com.itboye.mengwu.data.model.ShopCarBeanCopy;
import com.itboye.mengwu.data.repository.ShopCarResitory;

public class ShopCarPresenter extends BasePresenter implements
		IShopCar<ShopCarBean> {
	GoodsDetailBean.SkuCombinationBean bean;
	// 查詢購物車
	public static final String ShopCar_success = MainPresenter.class.getName()
			+ "_ShopCar_success";
	public static final String ShopCarFailEvent = MainPresenter.class.getName()
			+ "_ShopCar_fail";

	// 添加購物車
	public static final String ShopCarAdd_success = MainPresenter.class
			.getName() + "_ShopCarAdd_success";
	public static final String ShopCarAddFailEvent = MainPresenter.class
			.getName() + "_ShopCarAdd_fail";

	// 修改購物車
	public static final String ShopCarUpdate_success = MainPresenter.class
			.getName() + "_ShopCarUpdate_success";
	public static final String ShopCarUpdateFailEvent = MainPresenter.class
			.getName() + "_ShopCarUpdate_fail";

	// 刪除購物車
	public static final String ShopCarDelete_success = MainPresenter.class
			.getName() + "_ShopCarDelete_success";
	public static final String ShopCarDeleteFailEvent = MainPresenter.class
			.getName() + "_ShopCarDelete_fail";

	// 查询库存
	public static final String GoodsRemain_success = MainPresenter.class
			.getName() + "_GoodsRemain_success";
	public static final String GoodsRemainFailEvent = MainPresenter.class
			.getName() + "_GoodsRemain_fail";
	// 全部查询
	public static final String GoodsQueryALL_success = MainPresenter.class
			.getName() + "_GoodsQueryALL_success";
	public static final String GoodsQueryALLFailEvent = MainPresenter.class
			.getName() + "_GoodsQueryALL_fail";

	public ShopCarPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(ShopCarBean model) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(ShopCarAdd_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(ShopCarAddFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.add(model);// (model.getId());
	}

	@Override
	public void delete(ShopCarBean model) {
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(ShopCarDelete_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(ShopCarDeleteFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.delete(model);// (model.getId());
	}

	@Override
	public void update(ShopCarBean model) {
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(ShopCarUpdate_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(ShopCarUpdateFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.update(model);// (model.getId());
	}

	// 得到库存量
	@Override
	public void getInfo(ShopCarBean model) {
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(GoodsRemain_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(GoodsRemainFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.getInfo(model);
	}

	@Override
	public List<ShopCarBean> query(ShopCarBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void getShopcar(String uid) {
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(GoodsQueryALL_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(GoodsQueryALLFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.getShopcar(uid);
	}

	@Override
	public void deleteShopcar(StringBuilder uid) {
		// TODO Auto-generated method stub
		IShopCar<ShopCarBean> getShopCar = new ShopCarResitory(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar success");
						result.setEventTag(Tag_Success);
						result.setEventType(ShopCarDelete_success);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						Log.v("MainPresenter", "shopcar fail");
						result.setEventTag(Tag_Error);
						result.setEventType(ShopCarDeleteFailEvent);
						ShopCarPresenter.this.setChanged();
						ShopCarPresenter.this.notifyObservers(result);
					}
				});
		getShopCar.deleteShopcar(uid);
	}

}
